from dataclasses import asdict

from litemall.api.goods import Goods
from litemall.api.session_api import SessionApi
from litemall.api.http import HttpRequests


class GoodsApi:

    def __init__(self):
        self.token = SessionApi().login('user123', 'user123')
        self.http = HttpRequests(self.token)
        self.goods = Goods()

    def goods_list(self, goods: Goods):
        """商品搜索"""
        url = '/wx/goods/list'
        params = asdict(goods)
        r = self.http.get(url, params=params)
        return r

    def goods_detail(self, goods_id):
        """商品详情"""
        url = '/wx/goods/detail'
        params = {'id': goods_id}
        r = self.http.get(url, params=params)
        return r
